home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / boopsi / democlasslib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  3.3 KB  |  153 lines

  1. /* democlasslib.c -- demonstration of         :ts=8
  2.  * using a public image class from a library.
  3.  */
  4.  
  5. /*
  6. Copyright (c) 1989, 1990 Commodore-Amiga, Inc.
  7.  
  8. Executables based on this information may be used in software
  9. for Commodore Amiga computers. All other rights reserved.
  10. This information is provided "as is"; no warranties are made.
  11. All use is at your own risk, and no liability or responsibility
  12. is assumed.
  13. */
  14.  
  15. #include "sysall.h"
  16.  
  17. #define D(x)    x
  18.  
  19. struct  IntuitionBase   *IntuitionBase;
  20. struct Library    *MyClassBase;
  21.  
  22. Object    *NewObject();
  23.  
  24. ULONG    myiflags = CLOSEWINDOW;
  25.  
  26. struct Image    *myimage;
  27.  
  28. main()
  29. {
  30.     struct DrawInfo    *GetScreenDrawInfo();
  31.     struct Window     *OpenWindowTags();    /* in varargs.c for now */
  32.     struct Window    *w;
  33.     struct DrawInfo    *drinfo;
  34.  
  35.     openAll();    /* get libraries open    */
  36.  
  37.     D( printf("got myclass.library at %lx\n", MyClassBase ) );
  38.  
  39.     D( printf("about to openwindow\n") );
  40.     w = OpenWindowTags( NULL, 
  41.         WA_Title,    "Public Image Test Window",
  42.         WA_SimpleRefresh, TRUE,
  43.         WA_NoCareRefresh, TRUE,
  44.         WA_DepthGadget,    TRUE,
  45.         WA_DragBar,    TRUE,
  46.         WA_Left,    300,
  47.         WA_Top,        50,
  48.         WA_Width,    280,
  49.         WA_Height,    120,
  50.         WA_IDCMP,    myiflags,
  51.         WA_CloseGadget,    TRUE,
  52.             TAG_END );
  53.     D( printf("window at %lx\n ", w ) );
  54.     if ( w == NULL) cleanup( "couldn't open my window.\n");
  55.  
  56.     drinfo = GetScreenDrawInfo( w->WScreen );
  57.  
  58.     /* create an image from my public class    */
  59.     myimage =  (struct Image *) NewObject(  NULL,  "emboxclass",
  60.             IA_WIDTH, 20,
  61.             IA_HEIGHT, 10,
  62.                 TAG_END );
  63.  
  64. #define XPOS    (40)
  65. #define YPOS    (20)
  66. #define XPOS2    (XPOS + 30)
  67.  
  68.     /* draw the image    */
  69.     DrawImageState( w->RPort, myimage, XPOS, YPOS, IDS_NORMAL, drinfo );
  70.  
  71.     /* draw the image    */
  72.     DrawImageState( w->RPort, myimage, XPOS2, YPOS, IDS_SELECTED, drinfo );
  73.  
  74.     /* go away and be done    */
  75.     goHandleWindow( w );
  76.  
  77.     FreeScreenDrawInfo( w->WScreen, drinfo );
  78.     CloseWindow( w );
  79.  
  80.     cleanup( "all done, disposing image before closelibrary." );
  81. }
  82.  
  83. /*
  84.  * try to get the system to flushlibs
  85.  */
  86. inciteExpunge()
  87. {
  88.     void *mem;
  89.  
  90. #define LOTS_O_MEM    (2000000L)
  91.  
  92.     if ( mem = (void *) AllocMem( LOTS_O_MEM, 0 ) )
  93.     {
  94.     D( printf("GOT MEM %lx!\n", mem ) );
  95.         FreeMem( mem, LOTS_O_MEM );
  96.     }
  97. }
  98.  
  99. cleanup( str )
  100. char    *str;
  101. {
  102.     if (str) printf("%s\n", str);
  103.  
  104.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  105.  
  106.     DisposeObject( myimage );
  107.     D( printf("have disposed image.\n") );
  108.  
  109.     D( printf("close class library %lx\n", MyClassBase ) );
  110.     if (MyClassBase) CloseLibrary(MyClassBase);
  111.  
  112.     D( printf("expunge ... ") );
  113.     inciteExpunge();
  114.     D( printf("done\n") );
  115.  
  116.     exit (0);
  117. }
  118.  
  119. /* exits via cleanup() if failure    */
  120. openAll()
  121. {
  122.     if (!(IntuitionBase = 
  123.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)))
  124.     { cleanup("no V36 intuition library\n"); }
  125.  
  126.     if (!(MyClassBase=(struct Library *)OpenLibrary("myclass.library", 36L)))
  127.     { cleanup("no myclass.library\n"); }
  128. }
  129.  
  130. goHandleWindow( w )
  131. struct Window    *w;
  132. {
  133.     struct IntuiMessage *imsg;
  134.     for(;;)
  135.     {
  136.     WaitPort( w->UserPort );
  137.     while ( imsg = (struct IntuiMessage *) GetMsg( w->UserPort ) )
  138.     {
  139.         switch ( imsg->Class )
  140.         {
  141.         case CLOSEWINDOW:
  142.             ReplyMsg( (struct Message *) imsg );
  143.         return;
  144.  
  145.         default:
  146.         D( printf("unknown message \n", imsg->Class));
  147.         break;
  148.         }
  149.         ReplyMsg( (struct Message *) imsg );
  150.     }
  151.     }
  152. }
  153.